<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
   <link href="<s:url value="/resources"/>/css/style_new.css" rel="stylesheet" type="text/css" />
    <link href="<s:url value="/resources"/>/css/main_new.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <style>
html, body {
	margin: 0;			 
	padding: 0;
	 
    font-size: 85%;
}
</style>
    
  </head>
  
  <script type="text/javascript">  

			var qieye = 0;
			$(function() {
				$("#xinz").button();
				$("#chax").button();
				$("#shanc").button();
				$("#tib").button();
				$("#daoc").button();
				$("#daoc").hide();
				$("#fuz").button();
				$("#reset").button();
				loadTab(0);
				$("#datepicker").datepicker($.datepicker.regional["zh-CN"]);
				$("#datepicker1").datepicker($.datepicker.regional["zh-CN"]);
				$("#tabs").tabs(
						{
							select : function(event, ui) {
								var i = ui.index;
								if (i == '') {
									i = "0";
								}
								qieye = i;
								//alert(i);
								loadTab(i);
								//$("#myTab"+qieye).jqGrid('setGridParam',{url:'htJqgrid.action?index='+qieye,mtype:'post',page:1}).trigger("reloadGrid");
								// alert("aa");
								if (i == '1') {
									jQuery("#myTab=" + i).jqGrid('hideCol',
											[ "Verify" ]);
								}
								//return false;           
							}

						});
			});

			function loadTab(i) {
				var sign = true;
				if (i == '1')
					sign = false;
				$("#myTab" + i)
						.jqGrid(
								{
									url : 'findBuyGrid?index=' + i,
									datatype : 'json',
									mtype : 'post',
									colNames : [ '操作', '报单号', '报单单位名称', '煤种',
											'品种', '价格类型', '价格', '数量', '隶属行业',
											'报单日期','报单编码' ],
									colModel : [ {
										name : 'Verify',
										index : 'id',
										width : 80,
										align : "center",
										sortable : false
									}, {
										name : 'baodbh',
										index : 'baodbh',
										width : 120
									}, {
										name : 'baoddwname',
										index : 'baoddwname',
										width : 200
									}, {
										name : 'meizmc',
										index : 'meizmc',
										width : 80
									}, {
										name : 'pinzmc',
										index : 'pinzmc',
										width : 80
									}, {
										name : 'jiaglxmc',
										index : 'jiaglxmc',
										width : 60
									}, {
										name : 'danj',
										index : 'danj',
										width : 60
									}, {
										name : 'shul',
										index : 'shul',
										width : 60
									}, {
										name : 'lismc',
										index : 'lismc',
										width : 60
									}, {
										name : 'baodsj',
										index : 'baodsj',
										width : 80
									},{
									    name:'baodid',
									    index:'baodid',
									    width:80
									}],
									jsonReader : {
										repeatitems : false,
										id : 'baodid'
									},
									width: 1200,
									shrinkToFit : false,
									rowNum : 10,
									rowList : [ 10, 20, 30 ],
									pager : '#pager' + i,
									rownumbers : true,
									viewrecords : true,
									multiselect : sign,
									sortorder : 'desc',
									altRows : true,
									//caption: "报单列表",
									gridComplete : function() { //在此事件中循环为每一行添加修改和删除链接 
										var ids = jQuery("#myTab" + i).jqGrid(
												'getDataIDs');
										for ( var j = 0; j < ids.length; j++) {
											var id = ids[j];
											if (i == 1) {
												var jsv = $("#myTab" + i)
														.jqGrid('getRowData',
																id);
												//alert(id);
												//alert(jsv.danjzt);
												if (jsv.danjzt == 1) {
													verify = "<a href='#' style='color:#f60' onclick='Canel("
															+ id
															+ ")'>撤销</a>&nbsp;|&nbsp;<a href='#' style='color:#f60' onclick='select("
															+ id + ")'>查看</a>";
												} else if (jsv.danjzt == 6) {
													verify = "<a href='#' style='color:#f60' onclick='reCanel("
															+ id
															+ ")'>申请撤销</a>&nbsp;|&nbsp;<a href='#' style='color:#f60' onclick='select("
															+ id + ")'>查看</a>";
												} else {
													verify = "<a href='#' style='color:#f60' onclick='select("
															+ id + ")'>查看</a>";
												}

											} else {
												verify = "<a href='#' style='color:#f60' onclick='Verify("
														+ id
														+ ")'>编辑</a>&nbsp;|&nbsp;<a href='#' style='color:#f60' onclick='select("
														+ id + ")'>查看</a>";
											}
											jQuery("#myTab" + i).jqGrid(
													'setRowData', ids[j], {
														Verify : verify
													});
										}
									}
								});
				$("#myTab" + i).jqGrid('setGridHeight', '300px');
				$("#myTab" + i).jqGrid('hideCol', [ "baodid" ]);
			}

			// 查询
			function search() {
				//alert("aaa");  
				var formdata = $("#form1").serialize();
				$("#myTab" + qieye).jqGrid('setGridParam', {
					url : 'findBuyGrid?' +formdata+'&index='+qieye,
					mtype : 'post',
					page : 1
				}).trigger("reloadGrid");
			}

			function openwindow(url) {
				var sheight = screen.height - 70;
				var swidth = screen.width - 10;
				var winoption = "dialogHeight:" + sheight + "px;dialogWidth:"
						+ swidth
						+ "px;status:yes;scroll:yes;resizable:yes;center:yes";
				var result = window.showModalDialog(url, window, winoption);
				//alert(result);
				if (result == 1) {
					reloadbdxx();
				}
				return result;
			}

			function reloadbdxx() {
				window.location.href = "<s:url value='/'/>/jjjy/findBuyView";
			}

			function removeRow() {
				var s = $("#myTab0").jqGrid('getGridParam', 'selarrrow');
				if (s == "") {
					alert("请先选择报单，再点击删除！");
					return;
				}
				var url = "<s:url value='/'/>/jjjy/removeJjbd?baodid=" + s;
				$("#dialog-confirm").dialog({
					resizable : false,
					height : 140,
					modal : true,
					buttons : {
						"确认" : function() {
							$.post(url, function(data) {
								var json = eval('(' + data + ')');
								if (json.result == 1) {
									alert("删除成功！");
									reloadbdxx();
								} else {
									alert("删除失败！");
								}
							});
							$(this).dialog("close");
						},
						"返回" : function() {
							$(this).dialog("close");
						}
					}
				});
			}

			function submitRow() {
				var s = $("#myTab0").jqGrid('getGridParam', 'selarrrow');
				if (s == "") {
					alert("请先选择报单，再点击提交！");
					return;
				}
				var url = "<s:url value='/'/>/jjjy/submitJjbd?baodid=" + s;
				$("#dialog-confirm1").dialog({
					resizable : false,
					height : 140,
					modal : true,
					buttons : {
						"确认" : function() {
							$.post(url, function(data) {
								var json = eval('(' + data + ')');
								if (json.result == 1) {
									alert("提交成功！");
									reloadbdxx();
								} else {
									alert("提交失败！" + json.msg);
								}
							});
							$(this).dialog("close");
						},
						"返回" : function() {
							$(this).dialog("close");
						}
					}
				});

			}

			function copyRow() {
				var s = $("#myTab0").jqGrid('getGridParam', 'selarrrow');
				if (s == "") {
					alert("请先选择报单，再点击复制！");
					return;
				}
				var url = "<s:url value='/'/>/jjjy/copyJjbd?baodid=" + s;
				$("#dialog-confirm2").dialog({
					resizable : false,
					height : 140,
					modal : true,
					buttons : {
						"确认" : function() {
							$.post(url, function(data) {
								var json = eval('(' + data + ')');
								if (json.result == 1) {
									alert("复制成功！");
									reloadbdxx();
								} else {
									alert("复制失败！");
								}
							});
							$(this).dialog("close");
						},
						"返回" : function() {
							$(this).dialog("close");
						}
					}
				});
			}

			function Verify(id) { //单击修改链接的操作 
				
				if (id.id != undefined) {
					
					openwindow('<s:url value="/"/>/gpjy/bdxg4mfInfo?bdbh=' + id.id);
				} else {
					var bdbh = id.item(1).cells.item(3).innerHTML;
					openwindow('<s:url value="/"/>/gpjy/bdxg4mfInfo?bdbh=' + bdbh);
				}
			}

			function select(id) {
				if (id.id != undefined) {
					openwindow('<s:url value="/"/>/gpjy/bdcx4mfInfo?bdbh=' + id.id);
				} else {
					var bdbh = id.item(1).cells.item(3).innerHTML;
					openwindow('<s:url value="/"/>/gpjy/bdcx4mfInfo?bdbh=' + bdbh);
				}
			}

			//重置
			function resetSearch() {
				$('#list_search  input[type=text]').val('');
				$('#list_search select').val('-1');
			}

			function dc_excel() {
				form1.action = "/htgl/jytj_excel.action?index=0";
				form1.method = "post";
				form1.submit();
			}

			function Canel(id) {
				if (id.id != undefined) {
					openwindow('<s:url value="/"/>/gpjy/bdthInfo?bdzt=0&bdbh=' + id.id);
				} else {
					var bdbh = id.item(1).cells.item(2).innerHTML;
					openwindow('<s:url value="/"/>/gpjy/bdthInfo?bdzt=0&bdbh=' + bdbh);
				}
			}

			function reCanel(id) {
				if (id.id != undefined) {
					openwindow('<s:url value="/"/>/gpjy/bdthInfo?bdzt=8&bdbh=' + id.id);
				} else {
					var bdbh = id.item(1).cells.item(2).innerHTML;
					openwindow('<s:url value="/"/>/gpjy/bdthInfo?bdzt=8&bdbh=' + bdbh);
				}
			}
		</script>  
<body>  
<div class="container">  
<div class="containerbox">
<div class="btn-bar"> 
    <a href="#" class="btn" onclick= "openwindow('findBuyAddView')"><img src="<s:url value="/resources"/>/img/ico_23.gif" /><span>新增</span></a> 
    <a href="#" class="btn" onclick="removeRow();"><img src="<s:url value="/resources"/>/img/ico_25.gif" /> <span>删除</span></a>
    
    <a href="#" class="btn" onclick="submitRow();"><img src="<s:url value="/resources"/>/img/operate_pass.gif" /> <span>提报</span></a> 
    
    <!-- <a href="#" class="btn"><img src="<s:url value="/resources"/>/img/ico_27.gif" /> <span>导出excel</span></a>  -->
    <a href="#" class="btn" onclick="copyRow();"><img src="<s:url value="/resources"/>/img/ico_25.png" /> <span>复制</span></a> 
    
    </div>
<div class="search mt10" id="list_search">
<form id="form1" method="post">

<table id="list_search" cellpadding="0" cellspacing="0" border="0"> 
        <tr>
        	<td>报单单位:</td>
            <td><input type="text" class="form-textbox" style="width: 200px;" name="aa" /></td>
            <td>
                煤种:
            </td>
            <td>
				<div class="select"><div>
            	<select name="bb" class="form-textbox" style="width: 200px;">
            	<option value="-1" selected>==请选择==</option>
                   <c:forEach var="mz" items="${meiz}">
                   <option value="${mz.diccode}">
                   ${mz.dicname}
                   </option>
                   </c:forEach>
                 </select>
            	</div></div>            
            	 </td>            
            <td>
               品种 :
            </td>
            <td>
            	<div class="select"><div>
            	<select name="cc" class="form-textbox" style="width: 200px;">
            	<option value="-1" selected>==请选择==</option>
                   <c:forEach var="pz" items="${pinz}">
                   <option value="${pz.diccode}">
                   ${pz.dicname}
                   </option>
                   </c:forEach>
                 </select>
            	
            	</div></div>
             </td>
        </tr>        
        <tr>
       
        <td>隶属行业:</td>
        <td>
       <div class="select"><div>
            <select name="dd" class="form-textbox" style="width: 200px;">
                  <option value="-1" selected>==请选择==</option>
                   <c:forEach var="hy" items="${hangy}">
                   <option value="${hy.diccode}">
                   ${hy.dicname}
                   </option>
                   </c:forEach>
            </select>
        
        </div></div>
        </td>
        <td>发站（局）:</td>
        <td><input type="text" class="form-textbox" style="width: 200px;" name="ee" /></td>
        <td>到站（局）:</td>
        <td><input type="text" class="form-textbox" style="width: 200px;" name="ff" /></td>
        </tr>
        <tr>
        <td>价格:</td>
        <td><input type="text" class="form-textbox" style="width: 93px;" name="gg" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="form-textbox" style="width: 93px;" name="hh" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>数量:</td>
        <td><input type="text" class="form-textbox" style="width: 93px;" name="ii" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="form-textbox" style="width: 93px;" name="jj" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>报单日期:</td>
            <td>
            	<input id="datepicker" type="text" class="form-textbox" style="width: 93px;" name="kk" /> 
            	-- 
            	<input id="datepicker1" type="text" class="form-textbox" style="width: 93px;" name="ll" />
            </td>
        </tr>
        <tr>
    <td align="left" valign="middle" colspan="6">
<table border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td align="right" class="pr10 search-table-70">&nbsp;</td>
    <td align="left"><input name="" type="button" class="form-button-query form-button" value="查询" onclick="search();"/>
    <input name="" type="button" class="form-button-reset form-button" value="重置"  onclick="resetSearch();"/></td>
  </tr>
</table></td>
  </tr>
        
  </table> 
  </form>  
  </div>     
    <div id="tabs">
			<ul>
				<li><a href="#tabs-0">待提报</a></li>
				<li><a href="#tabs-1">已提报</a></li>
			</ul>
			<div id="tabs-0">
				<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager0" class="scroll"></div>
				<div id="message0" class="scroll"></div>
			</div>
			<div id="tabs-1">
				<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager1" class="scroll"></div>
				<div id="message1" class="scroll"></div>
			</div>

   </div>
   <div id="dialog-confirm" title="是否确认删除？"></div>
   <div id="dialog-confirm1" title="是否确认提报？"></div>
   <div id="dialog-confirm2" title="是否确认复制？"></div>
</div>
</div>
</body>
</html>
